#pragma once

#include "Mutex.h"

namespace Core
{
	template <class T>
	class Singleton
	{
	private:
		static T* ms_Singleton;

	protected:
		Singleton() { }

	public:
		static Mutex SingletonMutex;

		virtual ~Singleton() { }
		static T& GetSingleton()
		{
			return *GetSingletonPointer();
		}
		static T* GetSingletonPointer()
		{
			if(ms_Singleton==NULL)
			{
				SingletonMutex.Lock();
				if(ms_Singleton==NULL)
				{
					ms_Singleton = new T();
				}
				SingletonMutex.Unlock();
			}
			return ms_Singleton;
		}
	};

	template <class T>
	T* Singleton<T>::ms_Singleton = NULL;
	template <class T>
	Mutex Singleton<T>::SingletonMutex;

}
